using System;
using System.Collections.Generic;
using System.Text;
using DOMercury.Interfaces;

namespace DOMercury.Items
{
    /// <summary>
    /// Holds a list of PathItems.  Should always use this instead of PathItem when making plugins that affect Paths.  Even if they are only one path at a time
    /// </summary>
    public class ItemsList :IItem
    {
        private List<PathItem> items;
        private string type = ".*";
        private string dn = "Path(s)";
        private string desc = "Multiple Paths";

        public ItemsList(List<PathItem> Items)
        {
            items = Items;
            if (items.Count == 1)
            {
                dn = items[0].DisplayName;
                desc = items[0].Path;
            }
            findtype();
        }
        /// <summary>
        /// The list of PathItems this itemslist holds
        /// </summary>
        public List<PathItem> Items
        {
            get
            {
                return items;
            }
        }

        private void findtype()
        {
            bool diff = false;
            if (items.Count > 0)
            {
                for (int i = 0; i < (items.Count - 1); i++)
                {
                    if (items[i].ItemType != items[i + 1].ItemType)
                    {
                        diff = true;
                        break;
                    }
                }
                if (!diff)
                {
                    type = items[0].ItemType;
                }
            }
        }
        /// <summary>
        /// If the ItemsList holds multiple items, will be ".*".  If it holds only one PathItem, will be the type of that PathItem
        /// </summary>
        public string ItemType
        {
            get
            {
                return type;
            }
        }
        /// <summary>
        /// Returns List of Items or the displayname of the PathItem if holds only one.
        /// </summary>
        public string DisplayName
        {
            get
            {
              return dn;
            }
        }
        /// <summary>
        /// Either "Multiple Paths" or the Path of the PathItem if holds only one.
        /// </summary>
        public string DisplayDesc
        {
            get
            {
                return desc;
            }
        }

        public int CompareTo(object obj)
        {
            return DisplayName.CompareTo(((IItem)(obj)).DisplayName);
        }
    }

}
